package com.vmj.classfile.entity.constantinfo;

import com.vmj.classfile.ClassReader;
import com.vmj.classfile.entity.AbstractConstantInfo;
import com.vmj.classfile.entity.ConstantPool;

/**
 * Created by yangshoujun on 2017/8/6 下午1:54.
 */
public class ConstantInterfaceMethodRefInfo extends AbstractConstantInfo {

    int classIndex;
    int nameAndTypeIndex;
    ConstantPool constantPool;

    public ConstantInterfaceMethodRefInfo(ClassReader reader, ConstantPool constantPool) {
        super(reader);
        this.constantPool = constantPool;
    }

    public void parse() {
        classIndex = getReader().readTwoByte();
        nameAndTypeIndex = getReader().readTwoByte();
    }

    public int getClassIndex() {
        return classIndex;
    }

    @Override
    public ConstantPool getConstantPool() {
        return constantPool;
    }

    public String[] getNameAndDescriptor() {
        return constantPool.getNameAndType(this.nameAndTypeIndex);
    }

    public String getClassName() {
        return getConstantPool().getClassName(getClassIndex());
    }
}
